var o = getApp();

Page({
    data: {
        goodsId: 0,
        couponStoreGoods: {},
        writingText: "",
        goodsImg: [],
        thumb: ""
    },
    onLoad: function(o) {
        var t;
        "" !== (null !== (t = o.goodsId) && void 0 !== t ? t : "") && (this.setData({
            goodsId: parseInt(o.goodsId)
        }), this.getGoodsDetails(this.data.goodsId));
    },
    onReady: function() {},
    onShow: function() {},
    getGoodsDetails: function(t) {
        var s = this, n = o.getNetAddresss("goods.goods.get-goods-page");
        o._postNetWork({
            url: n,
            data: {
                id: Number(t)
            },
            success: function(o) {
                var t, n, e, a = o.data;
                1 == a.result && s.setData({
                    couponStoreGoods: null === (t = a.data.plugin) || void 0 === t ? void 0 : t.coupon_store_goods,
                    goodsImg: null === (n = a.data.get_goods) || void 0 === n ? void 0 : n.thumb_url,
                    thumb: null === (e = a.data.get_goods) || void 0 === e ? void 0 : e.thumb
                });
            }
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(o) {
                o.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var o = this.data.posterImg;
        wx.downloadFile({
            url: o,
            success: function(o) {
                wx.saveImageToPhotosAlbum({
                    filePath: o.tempFilePath,
                    success: function(o) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(o) {
                        "saveImageToPhotosAlbum:fail auth deny" === o.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(o) {
                                o.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(o) {
                        console.log(o);
                    }
                });
            }
        });
    },
    copyBtn: function(o) {
        var t = o.currentTarget.dataset.text;
        wx.setClipboardData({
            data: t,
            success: function(o) {
                wx.getClipboardData({
                    success: function(o) {
                        wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});